// Reverse digits of an integer.
// 
// Example1: x = 123, return 321
// Example2: x = -123, return -321


class Solution {
public:
    int reverse(int x) {
		
		if(x<10 && x>-10)
			return x;
		
		nflag =  1;		
		if(x < 0)
		{
			nflag = -1;
		}
		
		x = nflag*x;
		
		list<int> listNum;
		while(x>0)
		{
			listNum.push_back(x%10);
			x = x/10;
		}
		
		x = 0;
		
		list<int>::iterator itr;
		for(itr = listNum.begin() ; itr != listNum.end() ; itr++)
		{
			x = x*10 + (int)*itr;
		}
		
		return nflag*x;
	
			
        
    }
};